package com.qzy.reggie.service.impl;

import com.qzy.reggie.mapper.CategoryMapper;
import com.qzy.reggie.pojo.Category;
import com.qzy.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    /*@Override
    public PageResult queryCategoryList(Integer page, Integer pageSize) {
        // 使用Mybatis的PageHelper插件完成分页功能

        // 1.通过插件，设置分页信息
        PageHelper.startPage(page,pageSize);

        // 2.正常实现员工列表查询（此时不需要考虑分页）
        List<Category> categorys = categoryMapper.selectList();

        // 3.封装PageInfo对象，获取分页total
        PageInfo<Category> pageInfo = new PageInfo<>(categorys);

        // 最后封装分页结果对象
        return new PageResult(pageInfo.getTotal(),categorys);
    }*/

    @Override
    public List<Category> queryCategoryList(Category category) {
        return categoryMapper.selectList(category);
    }

    @Override
    public Category getCategoryById(Long id) {
        if(id == null){
            return null;
        }
        Category category = new Category();
        category.setId(id);
        return categoryMapper.selectOne(category);
    }




    @Override
    public Integer save(Category category) {

        return categoryMapper.insert(category);
    }



    @Override
    public Integer update(Category category) {
        return categoryMapper.update(category);
    }

    @Override
    public Integer deleteCategory(Long id) {
        return categoryMapper.delete(id);
    }

}
